//
//  RTVistorViewController.swift
//  Weibo
//
//  Created by Brisinga on 16/3/3.
//  Copyright © 2016年 Root. All rights reserved.
//

import UIKit

class RTVisitorViewController: UITableViewController {
    
    
    var isLogin :Bool = RTUserAcountViewModel.sharedAccountViewModel.userLogin
    
    // 重写lowadView
    override func loadView() {
        
        if isLogin {
        
            super.loadView()
            
        }else{
            
            setupVisitorView()
        }
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    
    
    // 加载访客界面
    private func setupVisitorView() {
        // 设置view
        view = visitorView
        
        // 添加leftBarButtonItem
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", target: self, action: "login")
 
        // 添加rightBarButtonItem
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", target: self, action: "login")
        
    }
    
    
    
    @objc private func login() {
        
        // 弹出登录页面
        let oauthVC = RTOAuthViewController()
        
        
        presentViewController(RTNavgationController(rootViewController:oauthVC), animated: true, completion: nil)
        
    }
    
    
    
    // 懒加载访客view
     lazy var visitorView: RTVisitorView = {
        
        let vview = RTVisitorView()
        
        vview.delegate = self
        
        return vview
        
    }()
    
    
}

extension RTVisitorViewController: RTVisitorViewDelegate {
    
    func visitorView(visitView: RTVisitorView, clickBtn: UIButton) {
        
        login()
    }
}
